package com.dal.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @program: spring-boot
 * @description: 线程池
 * @author: jian
 * @create: 2022-06-22 16:51
 **/
public class Demo03 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService exe = Executors.newFixedThreadPool(50);
        for (int i = 0; i < 10; i++) {
            //执行线程
            exe.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("1-->"+System.currentTimeMillis());
                }
            });

            exe.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("2-->"+System.currentTimeMillis());
                }
            });

            exe.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("3-->"+System.currentTimeMillis());
                }
            });

            exe.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("4-->"+System.currentTimeMillis());
                }
            });

            exe.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("5-->"+System.currentTimeMillis());
                }
            });
        }
        while (true){
            //判断线程是否执行结束
            if (exe.isTerminated()){
                System.out.println("运行结束");
                break;
            }
            Thread.sleep(2000);
        }
        exe.shutdown();
    }
}
